<template>
  <div id="app">
    <router-view/>
  </div>
</template>

<script>
import {getCartCount, getUserInfo} from "@/api/user";
import {getToken} from "@/utils/auth";

export default {
  name: 'App',
  mounted() {
    if (getToken()) {
      this.getUserInfo()
      this.getCartCount()
    }
  },
  methods: {
    //获取登录用户信息
    getUserInfo() {
      getUserInfo().then(res => {
        this.$store.dispatch('saveUserName', res.username)
      })
    },
    //获取购物车数量
    getCartCount() {
      getCartCount().then(res => {
        this.$store.dispatch('saveCartCount', res)
      })
    }
  }
}
</script>

<style lang="scss">
@import "assets/scss/reset.scss";
@import "assets/scss/config.scss";
@import "assets/scss/button.scss";
@import "assets/scss/base.scss";
</style>
